
//
//  RoomListCell.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/28.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "RoomListCell.h"
#import "UIButton+ButtonStyle.h"
#import "WYUserView.h"
#import "YHMarcros.h"

@interface RoomListCell ()
@property(nonatomic, strong)WYUserView *topView;

@property(nonatomic, strong)UIButton *discountButton;
@property(nonatomic, strong)UIButton *paymentButton;
@end
@implementation RoomListCell

- (void)awakeFromNib {
    [super awakeFromNib];
   
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.contentView);
        make.height.equalTo(self.contentView).multipliedBy(0.5);
    }];
    [self.contentView addSubview:self.discountButton];
    [self.discountButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.bottom);
        make.width.lessThanOrEqualTo(self.contentView);
        make.leading.equalTo(self.contentView.leading).offset(20);
        make.height.equalTo(self.contentView).multipliedBy(0.25);
    }];
    
    [self.contentView addSubview:self.paymentButton];
    [self.paymentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.discountButton.bottom);
        make.trailing.equalTo(self.contentView).offset(-10);
        
    }];

    
    

}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self.paymentButton layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleRight imageTitleSpace:0];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 10;
    frame.size.height -= 10;
    frame.origin.x += 10;
    frame.size.width -= 20;
    [super setFrame:frame];
    
  

}

- (void)paymentButtonClick
{
    if (self.block) {
        self.block();
    }
}
#pragma mark <懒加载>
- (UIView *)topView
{
    if (!_topView) {
        _topView = [[WYUserView alloc]init];
    }
    return _topView;
}

- (UIButton *)discountButton
{
    if (!_discountButton) {
        _discountButton = [[UIButton alloc]init];
        [_discountButton setImage:[UIImage imageNamed:@"property_icon_sale"] forState:UIControlStateNormal];
        [_discountButton setTitle:@"折扣优惠9.8折，最高优惠 100 元" forState:UIControlStateNormal];
        [_discountButton setTitleColor:RGBColor(102, 102, 102) forState:UIControlStateNormal];
        
    }
    return _discountButton;
}

- (UIButton *)paymentButton
{
    if (!_paymentButton) {
        _paymentButton = [[UIButton alloc]init];
        [_paymentButton setImage:[UIImage imageNamed:@"property_icon_arrow"] forState:UIControlStateNormal];
        [_paymentButton setTitle:@"立即预约" forState:UIControlStateNormal];
        [_paymentButton setTitleColor:kGlobalRedColor forState:UIControlStateNormal];
        [_paymentButton addTarget:self action:@selector(paymentButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _paymentButton;
}
@end
